<template>
  <div class="tab2">
    <tab-bar :tabBar="menuTabBar" :on-selected="onBarSelected"></tab-bar>
		<chart-overlap :chart-data = "chartOverlapData"></chart-overlap>
		</div>
</template>

<script>
import tabBar from '@/components/common/TabBar'
import chartOverlap from '@/components/common/ChartOverlap'
import remoteDAO from '@/common//remoteDAO'
import constant from '@/common/constant'

export default {
  name: 'month-chart',
  data () {
    return {
      menuTabBar: [{name: '近一月'}, {name: '近三月'}],
      msgBar: 0,
      chartOverlapData: {},
      tabBarIndex: 0
    }
  },
  components: {
    tabBar,
    chartOverlap
  },
  methods: {
    onBarSelected (index) {
      this.msgBar = index;
      this.$store.dispatch('ctrlLoading', true);
      this.$store.dispatch('ctrlError', false);
      this.fetchLastData(this.msgBar)
    },
    async fetchLastData () {
      try {
        const [res, index] = await Promise.all([
          remoteDAO.invoke(constant.InterfaceEnum.GET_LST_C_B_FUND, {
            type: 0,
            pType: this.msgBar == 0 ? 30 : 90
          }),
          remoteDAO.invoke(constant.InterfaceEnum.GET_DAYS_INDEX, {
            type: 1,
            pType: this.msgBar == 0 ? 30 : 90
          })
        ]);
//      in ['20170821','62676']
        console.log(res.xTime)
        res.xTime = index.TableInfo.map(item => item.date)
        res.jlr = res.in.map((v, i) => v - res.out[i])
        let indexCln = index.TableInfo.map(item => item.price)
        xTime = index.TableInfo.map(item => item.date)
        let {xTime, out, jlr: netNumber} = res
        this.chartOverlapData = {
          in: res.in,
          xTime,
          out,
          netNumber,
          indexData: indexCln
        }
        console.log(this.chartOverlapData)
      } catch (err) {
        this.$store.dispatch('showError');
      }
    }
  },
  created() {
    this.fetchLastData()
  }
}
</script>

<style lang="less" scoped>
  @import '../../../assets/css/common.less';
  @import '../../../assets/css/cssReset';
</style>
